package com.qf.deadletter;

import com.qf.util.ConnUtil;
import com.rabbitmq.client.*;
import org.junit.Test;

import java.io.IOException;

public class NormalConsumer {

    @Test
    public void consume() throws IOException {
        //1. 获取connection对象
        Connection connection = ConnUtil.getConnection();

        //2. 创建Channel对象
        Channel channel = connection.createChannel();

        //3. 消费普通队列
        channel.basicConsume("normal_queue",false,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费到普通队列中的消息：" + new String(body,"UTF-8"));

                channel.basicReject(envelope.getDeliveryTag(),false);
            }
        });

        System.in.read();

    }


}
